<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 3px 3px 3px 3px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item" >
                        <div id="typeName" class="layui-inline">
                            <label class="layui-form-label">业务类型名称</label>
                            <div class="layui-input-inline">
                                <input   type="text" name="typeName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">原文件名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sourceName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo"> </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar"> </script>

    </div>
</div>
<script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="/static/js/common.js"></script>
<style>
    .layui-table-cell {
        height: 100px;
        line-height: 100px;
    }

    .layui-tab img {
        width: 150px;
        height: 100px;
    }
</style>
<script>
    let typeName =  $.common.getUrlParam("typeName");
    let sourceId =  $.common.getUrlParam("sourceId");
    if(!sourceId){
        sourceId=-1;
    }
    var lay, form, table;
    layui.use(['form', 'table'], function () {
        lay = layui.jquery;
        form = layui.form;
        table = layui.table;
        let param={"typeName":null,"sourceId":null};
        if(typeName){
            $('#typeName').css("display","none");
            param.typeName=typeName;
        }
        if(sourceId){
            param.sourceId=sourceId;
        }
        table.render({
            elem: '#currentTableId',
            url: '/files/pages',
            toolbar: '#toolbarDemo',
            method: "post",
            request: {
                pageName: "pageNum",
                limitName: "pageSize"
            },
            contentType: "application/json; charset=utf-8",
            where: {
                param: param
            },
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'id', width: 65, title: 'ID', sort: true},
                {
                    field: 'url', width: 120, title: '访问路径', templet: function (a, e) {
                        if (a.url) {
                            return '<a style="color: #EC0634" target="_blank" href="' + a.url + '">查看原图</a>';
                        }
                        return '';
                    }
                },
                {
                    field: 'url', width: 150, title: '图片', templet: function (a, e) {
                        if (a.url) {
                            return '<img  src="' + a.url + '"/>';
                        }
                        return '';
                    }
                },
                {field: 'typeName', width: 160, title: '业务类型'},
                {field: 'itemNo', width: 160, title: '产品编号'},
                {field: 'fileName', width: 200, title: '文件名'},
                {field: 'sourceName', width: 200, title: '原文件名'},
                {field: 'fileSize', width: 120, title: '文件大小'},
                {field: 'weight', width: 120, title: '引用次数'},
                {
                    field: 'createTime',
                    width: 160,
                    title: '创建时间',
                    templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"
                },
                {field: 'updateUser', width: 120, title: '修改人'},
                {
                    field: 'updateTime',
                    width: 160,
                    title: '修改时间',
                    templet: "<div>{{layui.util.toDateString(d.updateTime, 'yyyy-MM-dd')}}</div>"
                },]],
            done: function (res, curr, count) {  //隐藏列
                if ($.common.userIsAdmin()) {
                    $("[data-field='updateUser']").css('display', 'none');
                    $("[data-field='updateTime']").css('display', 'none');
                }
            },
            limits: [5,10, 15, 20, 25, 50, 100, 500],
            limit: 10,
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            let qparams=data.field;
            if(param.typeName){
                qparams.typeName=param.typeName;
            }
            if(param.sourceId){
                qparams.sourceId=param.sourceId;
            }
            search(qparams);
            return false;
        });
    });

    function search(qparams) {
        table.reload('currentTableId', {
            page: {
                curr: 1
            }
            , where: {
                param: qparams
            }
        }, 'data');
    }
</script>

</body>
</html>
